package com.qipay.baas.mapper;

import com.qipay.baas.model.Cp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface CpMapper {
    @Delete({
        "delete from cp",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into cp (`type`, app_id, ",
        "secret_id, agent_id, fee_default_recharge, ",
        "cost_withdraw, fee_withdraw_advince, ",
        "withdraw_password, notify_url, ",
        "ip, bind_mobile, ",
        "create_time, account_state, ",
        "contract_state)",
        "values (#{type,jdbcType=TINYINT}, #{appId,jdbcType=CHAR}, ",
        "#{secretId,jdbcType=CHAR}, #{agentId,jdbcType=BIGINT}, #{feeDefaultRecharge,jdbcType=DECIMAL}, ",
        "#{costWithdraw,jdbcType=INTEGER}, #{feeWithdrawAdvince,jdbcType=DECIMAL}, ",
        "#{withdrawPassword,jdbcType=VARCHAR}, #{notifyUrl,jdbcType=VARCHAR}, ",
        "#{ip,jdbcType=VARCHAR}, #{bindMobile,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{accountState,jdbcType=TINYINT}, ",
        "#{contractState,jdbcType=TINYINT})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(Cp record);

    @InsertProvider(type=CpSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(Cp record);

    @Select({
        "select",
        "id, `type`, app_id, secret_id, agent_id, fee_default_recharge, cost_withdraw, ",
        "fee_withdraw_advince, withdraw_password, notify_url, ip, bind_mobile, create_time, ",
        "account_state, contract_state",
        "from cp",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="type", property="type", jdbcType=JdbcType.TINYINT),
        @Result(column="app_id", property="appId", jdbcType=JdbcType.CHAR),
        @Result(column="secret_id", property="secretId", jdbcType=JdbcType.CHAR),
        @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT),
        @Result(column="fee_default_recharge", property="feeDefaultRecharge", jdbcType=JdbcType.DECIMAL),
        @Result(column="cost_withdraw", property="costWithdraw", jdbcType=JdbcType.INTEGER),
        @Result(column="fee_withdraw_advince", property="feeWithdrawAdvince", jdbcType=JdbcType.DECIMAL),
        @Result(column="withdraw_password", property="withdrawPassword", jdbcType=JdbcType.VARCHAR),
        @Result(column="notify_url", property="notifyUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR),
        @Result(column="bind_mobile", property="bindMobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="account_state", property="accountState", jdbcType=JdbcType.TINYINT),
        @Result(column="contract_state", property="contractState", jdbcType=JdbcType.TINYINT)
    })
    Cp selectByPrimaryKey(Long id);

    @UpdateProvider(type=CpSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Cp record);

    @Update({
        "update cp",
        "set `type` = #{type,jdbcType=TINYINT},",
          "app_id = #{appId,jdbcType=CHAR},",
          "secret_id = #{secretId,jdbcType=CHAR},",
          "agent_id = #{agentId,jdbcType=BIGINT},",
          "fee_default_recharge = #{feeDefaultRecharge,jdbcType=DECIMAL},",
          "cost_withdraw = #{costWithdraw,jdbcType=INTEGER},",
          "fee_withdraw_advince = #{feeWithdrawAdvince,jdbcType=DECIMAL},",
          "withdraw_password = #{withdrawPassword,jdbcType=VARCHAR},",
          "notify_url = #{notifyUrl,jdbcType=VARCHAR},",
          "ip = #{ip,jdbcType=VARCHAR},",
          "bind_mobile = #{bindMobile,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "account_state = #{accountState,jdbcType=TINYINT},",
          "contract_state = #{contractState,jdbcType=TINYINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Cp record);
}